CFLAGS = -W -Wall -I.. -pthread -g -pipe $(CFLAGS_EXTRA)
RM = rm -rf
OUT = -o $@

ifeq ($(OS),Windows_NT)
  MSVC = ../../vc6
  RM = del /q /f
  OUT =
  CC = $(MSVC)/bin/cl
  CFLAGS = /MD /TC /nologo /W3 /I$(MSVC)/include /I..
  CFLAGS += /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86
  CFLAGS += $(CFLAGS_EXTRA)
else
  UNAME_S := $(shell uname -s)

  ifeq ($(UNAME_S),Linux)
    CFLAGS += -ldl
  endif

  ifeq ($(UNAME_S),Darwin)
  endif
endif

all: hello websocket server post multi_threaded upload auth

# To enable Lua in a server, uncomment following lines
LUA    = ../lua-5.2.3/src
#CFLAGS += -I$(LUA) -L$(LUA) -llua

server: server.c ../mongoose.c
	$(CC) server.c ../mongoose.c $(OUT)  $(CFLAGS)

hello: hello.c ../mongoose.c
	$(CC) hello.c ../mongoose.c $(OUT) $(CFLAGS)

websocket: websocket_html.c websocket.c ../mongoose.c
	$(CC) websocket.c websocket_html.c ../mongoose.c $(OUT)  $(CFLAGS)

post: post.c ../mongoose.c
	$(CC) post.c ../mongoose.c $(OUT) $(CFLAGS)

multi_threaded: multi_threaded.c ../mongoose.c
	$(CC) multi_threaded.c ../mongoose.c $(OUT) $(CFLAGS)

upload: upload.c ../mongoose.c
	$(CC) upload.c ../mongoose.c $(OUT) $(CFLAGS)

auth: auth.c ../mongoose.c
	$(CC) auth.c ../mongoose.c $(OUT) $(CFLAGS)

websocket_html.c: websocket.html
	perl mkdata.pl $< > $@

u:
	g++ unit_test.c -Wall -W -pedantic -lssl -g -O0 $(CFLAGS_EXTRA) && ./a.out

clean:
	-@$(RM) hello upload post websocket auth server multi_threaded websocket_html.c *.exe *.dSYM *.obj .*o
